var base = require('/base_info.js');
var utils = require('/utils/index.js');
Page({
  data: {
    invoiceTitleList: []
  },
  enterpriseNameInput (e) {
    // console.log(e.detail.value); 
    this.getList(e.detail.value);
  },
  // 点击选择发票抬头
  invoiceClick (e) {
    var that = this;
    var index = e.currentTarget.dataset.id;
    my.setStorageSync({
      key: 'invoice', // 缓存数据的key
      data: JSON.stringify(that.data.invoiceTitleList[index]), // 要缓存的数据
    });
    my.navigateBack({});
  },
  getList (keywords) {
    let that = this;
    my.showLoading();
    utils.getData('FindInvoice', {
      enterpriseName: keywords
    }, (res) => {
      my.hideLoading();
      that.setData({
        invoiceTitleList: res.data.data.data
      })
    }, err => {
      my.hideLoading();
      console.log(err);
    });
  },
  onLoad(query) {
    // 页面加载时
  },
  onReady() {
    // 页面加载完成
  },
  onShow() {
    // 页面显示
  },
  onHide() {
    // 页面隐藏
  },
  onUnload() {
    // 页面被关闭
  },
  onTitleClick() {
    // 标题被点击
  },
  onPullDownRefresh() {
    // 页面被下拉
  },
  onReachBottom() {
    // 页面被拉到底部
  },
  onShareAppMessage() {
    // 返回自定义分享信息
    return {
      title: my.getStorageSync({
        key: 'hotel_name', // 缓存数据的key
      }).data,
      desc: my.getStorageSync({
        key: 'my_app_description', // 缓存数据的key
      }).data,
      path: 'pages/index/index?share=true',
      success: function (e) {
        console.log(e);
      }
    };
  },
});
